#include<bits/stdc++.h>
using namespace std;
int n;
string pd,s;
set<string>st;
map<string,int>ds;
bool check(string s){
	int k=0,j=0;
	int cnt=0,fac=0,flag=0;
	while(s[j]>='0'&&s[j]<='9'){
		k++;
		if(s[j]!='0') flag=1;
		if(flag==0&&s[j]=='0') cnt++;
		fac=fac*10+(s[j]-'0');
		if(fac>255) return false;
		if(k>1&&cnt>0) return false;
		j++;
	}
	if(s[j]!='.'||k==0) return false;
	j++;
	cnt=fac=flag=k=0;
	while(s[j]>='0'&&s[j]<='9'){
		k++;
		if(s[j]!='0') flag=1;
		if(flag==0&&s[j]=='0') cnt++;
		fac=fac*10+(s[j]-'0');
		if(fac>255) return false;
		if(k>1&&cnt>0) return false;
		j++;
	}
	if(s[j]!='.'||k==0) return false;
	j++;
	cnt=fac=flag=k=0;
	while(s[j]>='0'&&s[j]<='9'){
		k++;
		if(s[j]!='0') flag=1;
		if(flag==0&&s[j]=='0') cnt++;
		fac=fac*10+(s[j]-'0');
		if(fac>255) return false;
		if(k>1&&cnt>0) return false;
		j++;
	}
	if(s[j]!='.'||k==0) return false;
	j++;
	cnt=fac=flag=k=0;
	while(s[j]>='0'&&s[j]<='9'){
		k++;
		if(s[j]!='0') flag=1;
		if(flag==0&&s[j]=='0') cnt++;
		fac=fac*10+(s[j]-'0');
		if(fac>255) return false;
		if(k>1&&cnt>0) return false;
		j++;
	}
	if(s[j]!=':'||k==0) return false;
	j++;
	cnt=fac=flag=k=0;
	while(s[j]>='0'&&s[j]<='9'){
		k++;
		if(s[j]!='0') flag=1;
		if(flag==0&&s[j]=='0') cnt++;
		fac=fac*10+(s[j]-'0');
		if(fac>65535) return false;
		if(k>1&&cnt>0) return false;
		j++;
	}
	if(s[j]=='\0'&&k) return true;
	else return false;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>pd>>s;
		if(pd=="Server"){
			if(check(s)){
				if(!st.count(s)) {st.insert(s);ds[s]=i;puts("OK");}
				else puts("FAIL");
			}
			else puts("ERR");
		}
		if(pd=="Client"){
			bool pri=check(s);
			if(st.count(s)) printf("%d\n",ds[s]);
			else if(!st.count(s)&&pri) puts("FAIL");
			else if(!pri) puts("ERR");
		}
	}
	
	return 0;
}
